package com.marc.apps.thatwasracist;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;

public class MainActivity extends Activity {

	private static ImageButton button_racist;
	private static MediaPlayer mediaPlayer;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		button_racist = (ImageButton) findViewById(R.id.button_racist);
		mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.racist);
		
		button_racist.setOnTouchListener(racistButtonTouchListener);
		
	}
	
	public OnTouchListener racistButtonTouchListener = new OnTouchListener() {
	    @Override
	    public boolean onTouch(View v, MotionEvent event) {
	        if(event.getAction() == MotionEvent.ACTION_DOWN) {
	        	button_racist.setImageResource(R.drawable.redbutton2);
	        	button_racist.setBackgroundResource(0);
	        } else if (event.getAction() == MotionEvent.ACTION_UP) {
	        	button_racist.setImageResource(R.drawable.redbutton);
	        	button_racist.setBackgroundResource(0);
	        	playAudio();
	        }
			return false;
	    }
	};
	
	public void playAudio(){
		mediaPlayer.start();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
